home *** CD-ROM | disk | FTP | other *** search
/ Mac Power 1997 December / MACPOWER-1997-12.ISO.7z / MACPOWER-1997-12.ISO / AMUG / PROGRAMMING / Raven 1.2.sit / Raven 1.2 / Source / Foundation / OS / ZExitAction.cpp < prev    next >
Text File  |  1997-07-27  |  2KB  |  93 lines

  1. /*
  2.  *  File:       ZExitAction.cpp
  3.  *  Summary:       Mixin for objects that need to do cleanup when the app exists abnormally.
  4.  *  Written by: Jesse Jones
  5.  *
  6.  *  Copyright ゥ 1997 Jesse Jones. 
  7.  *    For conditions of distribution and use, see copyright notice in ZTypes.h  
  8.  *
  9.  *  Change History (most recent first):    
  10.  *
  11.  *         <2>     7/27/97    JDJ        List is accessed through a function instead of a static.
  12.  *         <1>     4/13/97    JDJ        Created
  13.  */
  14.  
  15. #include <ZExitAction.h>
  16.  
  17. #include <Set.h>
  18.  
  19. #include <ZDebug.h>
  20.  
  21.  
  22. //-----------------------------------
  23. //    Types
  24. //
  25. typedef set<MExitAction*, less<MExitAction*>, allocator<MExitAction*> > ZActionList;
  26.  
  27.  
  28. // ===================================================================================
  29. //    Internal Functions
  30. // ===================================================================================
  31.  
  32. //---------------------------------------------------------------
  33. //
  34. // GetExitList
  35. //
  36. //---------------------------------------------------------------
  37. static ZActionList& GetExitList()
  38. {
  39.     static ZActionList actions;
  40.     
  41.     return actions;
  42. }
  43.  
  44. #pragma mark -
  45.  
  46. // ===================================================================================
  47. //    class MExitAction
  48. // ===================================================================================
  49.  
  50. //---------------------------------------------------------------
  51. //
  52. // MExitAction::~MExitAction
  53. //
  54. //---------------------------------------------------------------
  55. MExitAction::~MExitAction()
  56. {
  57.     ZActionList::iterator iter = GetExitList().find(this);
  58.     ASSERT(iter != GetExitList().end());
  59.     
  60.     GetExitList().erase(iter);
  61. }
  62.  
  63.  
  64. //---------------------------------------------------------------
  65. //
  66. // MExitAction::MExitAction
  67. //
  68. //---------------------------------------------------------------
  69. MExitAction::MExitAction()
  70. {
  71.     ASSERT(GetExitList().find(this) == GetExitList().end());
  72.     
  73.     GetExitList().insert(this);
  74. }
  75.  
  76.  
  77. //---------------------------------------------------------------
  78. //
  79. // MExitAction::DoExitActions                            [static]
  80. //
  81. //---------------------------------------------------------------
  82. void MExitAction::DoExitActions()
  83. {
  84.     ZActionList::iterator iter = GetExitList().begin();
  85.     while (iter != GetExitList().end()) {
  86.         MExitAction* action = *iter++;
  87.         
  88.         action->OnAbnormalExit();
  89.     }
  90. }
  91.  
  92.  
  93.